package com.sykj.manage.web;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sykj.manage.service.BisConfigService;
import com.sykj.manage.model.BisConfig;
import com.sykj.manage.model.SysParam;
import com.sykj.util.ManageBody;

@Controller
@RequestMapping("/big")
public class BigConfigController {

	@Autowired
	BisConfigService bisConfigService;

	@RequestMapping("/list")
	@ResponseBody
public ManageBody getList(Model model){
	List<BisConfig>getall=bisConfigService.getall();
	System.out.println(getall+"------------------------------");
	return ManageBody.getData(getall.size(), getall, "");
}

@RequestMapping("/goadd")
public String biadd(BisConfig b){
	return "add";
}

@RequestMapping("/add")
public String addConfig (BisConfig b){
	//生成ID号
	b.setConfig_id(String.valueOf(System.currentTimeMillis()));
	b.setCreate_time(new Date());
	b.setModify_time(new Date());
	bisConfigService.add(b);
	return "redirect:/manage/basic.html";
}
@RequestMapping("/up")
@ResponseBody
public ManageBody updateBis (BisConfig b){
	Date day = new Date();
	b.setModify_time(day);
	int xg=bisConfigService.updateBis(b);
	System.out.println("修改了"+xg+"条数据,ID号是"+b.getConfig_id());
	return ManageBody.getData(xg, "", "success");
}
@RequestMapping("/upid/{bis}")
@ResponseBody
public BisConfig updateid(@PathVariable("bis") String id){
	BisConfig did=bisConfigService.updatecx(id);
	return did;
	
}

@RequestMapping("/deleteConfig/{Config_id}")
@ResponseBody
public ManageBody deleteConfig(@PathVariable("Config_id") String config_id){
	int de=bisConfigService.deleteConfig(config_id);
	if (de>0) {
		System.out.println("删除了"+de+"条数据,ID是"+ config_id);
		return ManageBody.getData(1, de, "");
	}else {
		System.out.println("删除了"+de+"条数据,ID是"+ config_id);
		return ManageBody.getData(1, de, "");
	}
	
}

@RequestMapping("/getparam")
@ResponseBody
public ManageBody getparam(){
	SysParam getparam = bisConfigService.getparam();
	System.out.println(getparam+"------------2222222222222222------------------");
	return ManageBody.getData(1, getparam, "");
	
}

@RequestMapping("/getparams")
@ResponseBody
public ManageBody getparams(){
	SysParam getparams = bisConfigService.getparams();
	System.out.println(getparams+"------------2222222222222222------------------");
	return ManageBody.getData(1, getparams, "");
	
}

//循环查出数据装进sessi里面
		@RequestMapping("/allsysparamKey")
		@ResponseBody
		public Map<String, SysParam> allsysparamKey(HttpSession session){
			Map<String, SysParam> paramMaps = bisConfigService.allSysparamdao();
			session.setAttribute("sysparam", paramMaps);
			System.out.println("&&&"+paramMaps);
			return paramMaps;
		}
	
		//修改先从sessi里拿出来然后在装进list拿出来修改
				@RequestMapping("/update")
				@ResponseBody
				public Map<String, SysParam> update(String exchange_beauty, String beauty_overtime ,HttpSession session){
					Map<String, SysParam> paramMaps = (Map<String, SysParam>) session.getAttribute("sysparam");
					SysParam sysParam1 = paramMaps.get("exchange_beauty");
					SysParam sysParam2 = paramMaps.get("beauty_overtime");
					
				
					
					List<SysParam> paramsList = new ArrayList<SysParam>();
					sysParam1.setParam_value(exchange_beauty);
					paramsList.add(sysParam1);
					sysParam2.setParam_value(beauty_overtime);
					paramsList.add(sysParam2);
					
					
					bisConfigService.updateSysParam(paramsList);
					return paramMaps;
				}
}
